(function(){
    nsbase.resources = new ResourcesFunc();
    nsbase.resources.rebuildObject();

    function ResourcesFunc() {
        var _self = this;

        function _init() {
            _self.repository = ResourcesRepository;
            _self.getString = getString;
            _self.rebuildObject = rebuildObject;
        }

        function ResourcesRepository(resourcesObj) {
            var me = this;
            $.extend(true, me, resourcesObj);
        }

        function getString(resourceKey) {
            var index = resourceKey.indexOf(".");
            var lastIndex = resourceKey.lastIndexOf(".");
            if (index > 0 && index == lastIndex && lastIndex < resourceKey.length - 1) {
                var keys = resourceKey.split(".");
                var typeName = keys[0];
                var resouceName = keys[1];
                var repository = _self[typeName];
                if (repository) {
                    var resource = repository[resouceName];
                    if (resource) {
                        return resource;
                    }
                }
            }
            return null;
        }

        function rebuildObject() {
            var cache = {};
            for (var type in _self) {
                if (_self.hasOwnProperty(type)) {
                    var repository = _self[type];
                    if (repository instanceof ResourcesRepository) {
                        for (var key in repository) {
                            if (repository.hasOwnProperty(key)) {
                                var value = repository[key];
                                if (typeof value == "string") {
                                    cache[key] = value;
                                }
                            }
                        }
                    }
                }
            }
        }

        _init();
    };

})();